package io.renren.modules.car.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.car.entity.CarBuyerMiddleEntity;
import io.renren.modules.car.service.CarBuyerMiddleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 买家-车辆中间表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-09-17 11:28:02
 */
@RestController
@RequestMapping("car/carbuyermiddle")
public class CarBuyerMiddleController {
    @Autowired
    private CarBuyerMiddleService carBuyerMiddleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("car:carbuyermiddle:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carBuyerMiddleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("car:carbuyermiddle:info")
    public R info(@PathVariable("id") Integer id){
        CarBuyerMiddleEntity carBuyerMiddle = carBuyerMiddleService.getById(id);

        return R.ok().put("carBuyerMiddle", carBuyerMiddle);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("car:carbuyermiddle:save")
    public R save(@RequestBody CarBuyerMiddleEntity carBuyerMiddle){
        carBuyerMiddle.setCreateTime(new Date());
        carBuyerMiddle.setUpdateTime(new Date());
        carBuyerMiddleService.save(carBuyerMiddle);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("car:carbuyermiddle:update")
    public R update(@RequestBody CarBuyerMiddleEntity carBuyerMiddle){
        ValidatorUtils.validateEntity(carBuyerMiddle);
        carBuyerMiddle.setUpdateTime(new Date());
        carBuyerMiddleService.updateById(carBuyerMiddle);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("car:carbuyermiddle:delete")
    public R delete(@RequestBody Integer[] ids){
        carBuyerMiddleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
